package com.zqxq.lottery.entity.o2o.sys;

import com.baomidou.mybatisplus.plugins.Page;
import com.zqxq.common.utils.DispatcherUtils;
import com.zqxq.common.utils.PageCopy;
import com.zqxq.lottery.entity.po.sys.SysMsgPO;
import com.zqxq.lottery.entity.vo.sys.SysMsgVO;

import java.util.ArrayList;
import java.util.List;

/**
 * @Description ：
 * @Author ： 解风
 * @Date ： 2018/03/14 16:14
 */
public class SysMsgO2O {

    public static SysMsgVO toVO(SysMsgPO po) {
        if (po == null) {
            return null;
        }
        SysMsgVO sysMsgVO = new SysMsgVO();
        sysMsgVO.setId(DispatcherUtils.parseString(po.getId()));
        sysMsgVO.setTheme(po.getTheme());
        sysMsgVO.setContent(po.getContent());
        sysMsgVO.setSort(DispatcherUtils.parseString(po.getSort()));
        sysMsgVO.setStatus(DispatcherUtils.parseString(po.getStatus()));
        sysMsgVO.setType(DispatcherUtils.parseString(po.getType()));
        sysMsgVO.setCreateTime(DispatcherUtils.parseDateTimeStr(po.getCreate_time()));
        sysMsgVO.setUpdateTime(DispatcherUtils.parseDateTimeStr(po.getUpdate_time()));
        return sysMsgVO;
    }


    public static Page<SysMsgVO> toPageVO(Page<SysMsgPO> page){
        Page<SysMsgVO> result = PageCopy.copyProperty(page, null);
        if(page != null){
            List<SysMsgPO> poList = page.getRecords();
            List<SysMsgVO> voList = toVOList(poList);
            result.setRecords(voList);
        }
        return result;
    }

    public static SysMsgPO toPO(SysMsgVO vo) {
        if (vo == null) {
            return null;
        }
        SysMsgPO sysMsgPO = new SysMsgPO();
        sysMsgPO.setId(DispatcherUtils.parseLong(vo.getId()));
        sysMsgPO.setTheme(vo.getTheme());
        sysMsgPO.setContent(vo.getContent());
        sysMsgPO.setSort(DispatcherUtils.parseInteger(vo.getSort()));
        sysMsgPO.setStatus(DispatcherUtils.parseInteger(vo.getStatus()));
        sysMsgPO.setType(DispatcherUtils.parseInteger(vo.getType()));
        sysMsgPO.setCreate_time(DispatcherUtils.parseDateTime(vo.getCreateTime()));
        sysMsgPO.setUpdate_time(DispatcherUtils.parseDateTime(vo.getUpdateTime()));
        return sysMsgPO;
    }

    public static List<SysMsgVO> toVOList(List<SysMsgPO> list){
        List<SysMsgVO> result = new ArrayList<>();
        if(list != null && list.size() > 0){
            for (SysMsgPO po : list) {
                result.add(toVO(po));
            }
        }
        return result;
    }


}
